package tw.com.book.task01;

import java.util.UUID;

import com.parse.Parse;

import tw.com.book.R;
import tw.com.book.api.task01.Task01Service;
import tw.com.book.componet.CommonUtils;
import tw.com.book.componet.IssueBussinessException;
import tw.com.book.core.task01.Task01ServiceImpl;
import tw.com.book.dto.Task01DTO;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * 新增iisu
 * 
 * @author Andy
 * 
 */
public class AddIssueActivity extends Activity {

	private Task01DTO dto = new Task01DTO();

	private Task01Service service = new Task01ServiceImpl();

	private Button saveIssueBtn;

	private transient EditText title;
	private transient EditText content;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.add_issue);

		this.title = (EditText) this.findViewById(R.id.title);
		this.content = (EditText) this.findViewById(R.id.coent);

		this.saveIssueBtn = (Button) this.findViewById(R.id.saveIssueBtn);
		this.saveIssueBtn.setOnClickListener(new SaveAction());

	}

	private class SaveAction implements OnClickListener {

		@Override
		public void onClick(View v) {
			try {

				dto.setCreateUser("AAA");
				dto.setStatus("A");
				dto.setUuid(UUID.randomUUID().toString());
				dto.setTitle(title.getText().toString());
				dto.setContent(content.getText().toString());
				dto.setNowDate(CommonUtils.getDate());
				dto.setNowTime(CommonUtils.getTime());

				AddIssueActivity.this.service.crateIssue(dto,
						AddIssueActivity.this);
				AddIssueActivity.this.finish();
				Toast.makeText(AddIssueActivity.this, "新增成功",
						Toast.LENGTH_SHORT).show();
			} catch (IssueBussinessException e) {
				Toast.makeText(AddIssueActivity.this, e.getMessage(),
						Toast.LENGTH_SHORT).show();
				
			}

		}
	}

}
